package cc.yihy.spider.util;


import cc.yihy.spider.core.Image;
import com.overzealous.remark.IgnoredHtmlElement;
import com.overzealous.remark.Options;
import com.overzealous.remark.Remark;
import com.overzealous.remark.convert.DocumentConverter;


/**
 * @Package: cc.yihy.util
 * @date: 2017/11/21 15:14
 * @author: Yihy
 * @version: V1.0
 * @Description:
 */
public class MarkdownUtils {

    private static Options github;
    private static Remark remark;

    static {
        github = Options.github();
        github.ignoredHtmlElements.add(IgnoredHtmlElement.create("img", "data-original-src"));
        github.inlineLinks = true;

        remark = new Remark(github);
        DocumentConverter converter = remark.getConverter();

        converter.addInlineNode(new Image(), "img");
    }


    public static String convertHtmlToMarkDown(String html) {
        if (html == null || html.length() == 0) return html;
        return remark.convert(html);
    }

}
